/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.yunhoo.pay.util;

import com.yunhoo.base.model.Person;



import com.yunhoo.sys.db.util.IbatisTemplate;
import com.yunhoo.sys.util.common.EmailTool;
import com.yunhoo.sys.util.common.LoginParam;
import com.yunhoo.sys.util.tree.TreeUtil;
import java.util.HashMap;
import java.util.Map;
import javax.faces.context.FacesContext;
import org.richfaces.event.TreeSelectionChangeEvent;

/**
 *
 * @author Administrator
 */
public class ToolsMethed {

//    public static void selectedTool(TreeSelectionChangeEvent event, Object param) {
//        param = (Object) TreeUtil.listener(event);
//    }
//
//    public static String getPayApplicationNumber() {
//        String ExpenseMaxNumber = (String) IbatisTemplate.query("payApp.maxPayApplicationNumber", curOrgCode().trim());
//        if (ExpenseMaxNumber == null || ExpenseMaxNumber.length() == 0) {
//            return ExpenseMaxNumber = "000001";
//        }
//        ExpenseMaxNumber = String.format("%06d%n", Integer.parseInt(ExpenseMaxNumber.trim()) + 1);
//        return ExpenseMaxNumber.trim();
//    }
//
//    /**
//     * 设置支出证明单编号
//     */
//    public static String getCostProofNumber() {
//        String ExpenseMaxNumber = (String) IbatisTemplate.query("costProof.maxCostProofNumber", curOrgCode().trim());
//        if (ExpenseMaxNumber == null || ExpenseMaxNumber.length() == 0) {
//            return ExpenseMaxNumber = "000001";
//        }
//        ExpenseMaxNumber = String.format("%06d%n", Integer.parseInt(ExpenseMaxNumber.trim()) + 1);
//        return ExpenseMaxNumber.trim();
//    }
//
//    public static String getMaxNumber() {
//        String ExpenseMaxNumber = (String) IbatisTemplate.query("loanbill.maxExpenseNumber", curOrgCode().trim());
//        if (ExpenseMaxNumber == null || ExpenseMaxNumber.length() == 0) {
//            ExpenseMaxNumber = "000001";
//            return ExpenseMaxNumber;
//        }
//        ExpenseMaxNumber = String.format("%06d%n", Integer.parseInt(ExpenseMaxNumber.trim()) + 1);
//        return ExpenseMaxNumber.trim();
//    }
//
//    public static String getAccountMaxNumber() {
//        String ExpenseMaxNumber = (String) IbatisTemplate.query("expensevoucher.maxExpenseAccountNumber", curOrgCode().trim());
//        if (ExpenseMaxNumber == null || ExpenseMaxNumber.length() == 0) {
//            ExpenseMaxNumber = "000001";
//            return ExpenseMaxNumber;
//        }
//        ExpenseMaxNumber = String.format("%06d%n", Integer.parseInt(ExpenseMaxNumber.trim()) + 1);
//        return ExpenseMaxNumber.trim();
//    }
//
//    public static String getTravelMaxNumber() {
//        String ExpenseMaxNumber = (String) IbatisTemplate.query("travelcost.maxExpensetravelNumber", curOrgCode().trim());
//        if (ExpenseMaxNumber == null || ExpenseMaxNumber.length() == 0) {
//            ExpenseMaxNumber = "000001";
//            return ExpenseMaxNumber;
//        }
//        ExpenseMaxNumber = String.format("%06d%n", Integer.parseInt(ExpenseMaxNumber.trim()) + 1);
//        return ExpenseMaxNumber.trim();
//    }
//
//    public static String getAgroupMaxNumber() {
//        String ExpenseMaxNumber = (String) IbatisTemplate.query("abroadGroup.maxExpenseAgroupNumber", curOrgCode().trim());
//        if (ExpenseMaxNumber == null || ExpenseMaxNumber.length() == 0) {
//            ExpenseMaxNumber = "000001";
//            return ExpenseMaxNumber;
//        }
//        ExpenseMaxNumber = String.format("%06d%n", Integer.parseInt(ExpenseMaxNumber.trim()) + 1);
//        return ExpenseMaxNumber.trim();
//    }
    public static String getPayFileMaxNumber() {
        String ExpenseMaxNumber = (String) IbatisTemplate.query("file.maxPayFileNumber", curOrgCode().trim());
        if (ExpenseMaxNumber == null || ExpenseMaxNumber.length() == 0) {
            return "000001";
        }
        ExpenseMaxNumber = String.format("%06d%n", Integer.parseInt(ExpenseMaxNumber.trim()) + 1);
        return ExpenseMaxNumber.trim();
    }

//    public static String getCostStandardMaxNumber() {
//        String ExpenseMaxNumber = (String) IbatisTemplate.query("maxCostStandardNumber", null);
//        if (ExpenseMaxNumber == null || ExpenseMaxNumber.length() == 0) {
//            return ExpenseMaxNumber = "000001";
//        }
//        ExpenseMaxNumber = String.format("%06d%n", Integer.parseInt(ExpenseMaxNumber.trim()) + 1);
//        return ExpenseMaxNumber.trim();
//    }
    public static String getClassCodeMaxNumber() {
        Map map = paramMap();
        String ExpenseMaxNumber = (String) IbatisTemplate.query("classCode.maxClassCodeNumber", map);
        if (ExpenseMaxNumber == null || ExpenseMaxNumber.length() == 0) {
            return ExpenseMaxNumber = "01";
        }
        ExpenseMaxNumber = String.format("%02d%n", Integer.parseInt(ExpenseMaxNumber.trim()) + 1);
        return ExpenseMaxNumber.trim();
    }

    public static void sendMail(Person sender, Person receiver, String title, String content) {
        String recAddr = receiver.getEmail().trim();
        EmailTool.sendMail(sender.getEmail().trim(), recAddr.trim(), sender.getEmailPwd().trim(), title, content);
    }

    private static Map paramMap() {
        Map map = new HashMap();
        map.put("orgCode", LoginParam.getOrg().getCode());
        map.put("iyear", LoginParam.getIyear());
        return map;
    }

    private static String curOrgCode() {
        return LoginParam.getOrg().getCode();
    }
}
